<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .mask{
            background-color: black;
            opacity: 0.6;
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            z-index: 10;
        }
        .modal{
            background-color: white;
            width: 500px;
            height: 300px;
            position: fixed;
            top: 60px;
            left: 50%;
            margin-left: -250px;
            z-index: 12;
        }
        .hide{
            display: none;
        }
    </style>
</head>
<body>

    <p><input type="button" value="添加主机" id="add-host"></p>

    <h3>取数据(对象)</h3>
    <table width="500" border="1">
        <thead>
        <tr>
            <th>ID</th>
            <th>主机名</th>
            <th>IP</th>
            <th>端口</th>
            <th>部门</th>
        </tr>
        </thead>
        <tbody>
        {% for foo in h1 %}
            <tr>
            <td>{{ foo.id }}</td>
            <td>{{ foo.hostname }}</td>
            <td>{{ foo.ip }}</td>
            <td>{{ foo.port }}</td>
            <td>{{ foo.business.caption }}</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>

    <h3>取数据(字典)</h3>
    <table width="500" border="1">
        <thead>
        <tr>
            <th>ID</th>
            <th>主机名</th>
            <th>IP</th>
            <th>端口</th>
            <th>部门</th>
        </tr>
        </thead>
        <tbody>
        {% for foo in h2 %}
            <tr>
            <td>{{ foo.id }}</td>
            <td>{{ foo.hostname }}</td>
            <td>{{ foo.ip }}</td>
            <td>{{ foo.port }}</td>
            <td>{{ foo.business__caption }}</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>

    <h3>取数据(元组)</h3>
    <table width="500" border="1">
        <thead>
        <tr>
            <th>ID</th>
            <th>主机名</th>
            <th>IP</th>
            <th>端口</th>
            <th>部门</th>
        </tr>
        </thead>
        <tbody>
        {% for foo in h3 %}
            <tr>
            <td>{{ foo.0 }}</td>
            <td>{{ foo.1 }}</td>
            <td>{{ foo.2 }}</td>
            <td>{{ foo.3 }}</td>
            <td>{{ foo.4 }}</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>

    <div class="mask hide"></div>
    <form action="/host/host/" method="post">
        <div class="modal hide">
            <input type="text" placeholder="主机名" name="hostname">
            <input type="text" placeholder="IP" name="ip"><br>
            <input type="text" placeholder="端口" name="port">
            <select name="business">
                {% for foo in b_list %}
                    <option value="{{ foo.id }}">{{ foo.caption }}</option>
                {% endfor %}
            </select>
            <input type="submit" value="提交">
            <input type="button" value="取消" id="cancel">
        </div>
    </form>
    <script src="/static/js/jquery-1.12.4.js"></script>
    <script>
        $(function(){
            $('#add-host').click(function () {
                $('.mask,.modal').removeClass('hide');
            });

            $('#cancel').click(function () {
                $('.mask,.modal').addClass('hide');
            });

        })



    </script>

</body>
</html>